<template>
  <div class="app-container">
    <el-form label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="用工单号" prop="taskNumber">
            <el-input v-model="this.taskNumber" :disabled="true" maxlength="30"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="用工时间" prop="needTime">
            <el-input v-model="this.needTime" :disabled="true" maxlength="30"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="18">
          <template v-for="item in operationNeedList">
            <h5>班次 {{item.timeShiftName}}</h5>
            <PostTable :tableData="item.timeShiftValue" :disabled="false"></PostTable>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="this.remark" :disabled="true" type="textarea" ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="updateOperationNeed">提 交</el-button>
    </div>
  </div>
</template>

<script>
  import { viewOperationNeed , updateOperationNeed } from "@/api/job/operationNeed/operationNeed";
  import { PostTable } from "../components"
  export default {
    components: { PostTable },
    name: "attendanceGroup",
    created() {
      this.viewOperationNeed();
    },
    data() {
      return {
        // 表格数据
        operationNeedList: [],
        firstOperationNeedList: [],
        // 是否显示弹出层（数据权限）
        openDataScope: false,
        menuExpand: false,
        menuNodeAll: false,
        deptExpand: true,
        deptNodeAll: false,
        operationNeedId: this.$route.query.operationNeedId,
        taskNumber: undefined,
        needTime: undefined,
        remark: undefined,
        defaultProps: {
          children: "children",
          label: "label",
        },
      };
    },

    methods: {
      viewOperationNeed() {
        viewOperationNeed(this.operationNeedId).then(es => {
          this.operationNeedList = es.data.timeShiftData,
            this.firstOperationNeedList = JSON.parse(JSON.stringify(this.operationNeedList)),
            this.taskNumber = es.data.taskNumber,
            this.needTime = es.data.needTime
            if(String(es.data.remark) != "null"){
              this.remark = es.data.remark
            }
        })
      },
      updateOperationNeed() {
        this.operationNeedList.forEach(function(item, index) {
          item.timeShiftValue.forEach(function(v,index) {
            if ('' == String(v.manNumber)){
              alert("数据有空值");
              throw "";
            }
            if ('' == String(v.womanNumber)){
              alert("数据有空值");
              throw "";
            }
            if (Number(v.manNumber) < 0){
              alert("数据有负数");
              throw "";
            }
            if (Number(v.womanNumber) < 0){
              alert("数据有负数");
              throw "";
            }
            if (String(v.manNumber).indexOf('.') != -1) {
              alert("数据有小数");
              throw "";
            }
            if (String(v.womanNumber).indexOf('.') != -1) {
              alert("数据有小数");
              throw "";
            }
          })
        })
        const data = {
          operationNeedList: this.operationNeedList,
          taskNumber: this.taskNumber,
          needTime: this.needTime,
          remark: this.remark,
          operationNeedId : this.operationNeedId,
          firstOperationNeedList : this.firstOperationNeedList
        }
        updateOperationNeed(data).then(es => {
          this.msgSuccess("提交成功");
          this.open = false;
          this.getOperationNeedList()
        })
      },
    },
  };
</script>
